package annotation;

import jakarta.servlet.annotation.WebServlet;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-07-12
 * Time:17:54
 */
public class MyTomcat {
    private static HashMap<String , Object> map = new HashMap<>();
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName("annotation.HiServlet");
        WebServlet annotation = aClass.getAnnotation(WebServlet.class);
        System.out.println(annotation);//@jakarta.servlet.annotation.WebServlet(loadOnStartup=-1, initParams={@jakarta.servlet.annotation.WebInitParam(description="", name="aa", value="A"), @jakarta.servlet.annotation.WebInitParam(description="", name="bb", value="B")}, urlPatterns={"/hiServlet"}, displayName="", name="", largeIcon="", description="", asyncSupported=false, smallIcon="", value={})
        String name = annotation.name();
        if (!map.containsKey(name)) {
            Object o = aClass.getDeclaredConstructor().newInstance();
            map.put(name , o);
        }
        System.out.println(map.get(name));//annotation.HiServlet@7506e922
    }
}
